package com.lmy.product.web;

import com.lmy.product.entity.CategoryEntity;
import com.lmy.product.service.CategoryService;
import com.lmy.vo.CategoryLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller

public class IndexController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping({"/", "/index"})
    public String indexPage(Model model) {

        //TODO查出所有的一级分类
        List<CategoryEntity> categoryEntities = categoryService.selectOneLevel();
        model.addAttribute("categorys", categoryEntities);
        return "index";
    }

    //index/catalog.json
    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String, List<CategoryLevelVo>> getCatalogJson(){
        Map<String, List<CategoryLevelVo>> map = categoryService.getCatalogJson();
        return map;
    }



}
